import { ILv70DramaStepCommand } from "../interfaces/ILv70DramaStepCommand";
import { TDrama } from "../../../../../Message/Db/Tables/TDrama";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
//class Lv70OpPlayerMove
    
    export  class Lv70OpPlayerMove implements ILv70DramaStepCommand
    {
        

        public call(arg1: TDrama, arg2: Function=null): void
        {
            this._callback = arg2;
            this._points = this.parseTargetPoints(arg1);
            if (this._points.length > 1) 
            {
                this._points.shift();
            }
            flash.utils.setTimeout(this.takeNextRoute, 560);
            return;
        }

        public takeNextRoute(): void
        {
            var loc3=null;
            var loc1=RolePlayer.instance;
            if (this._points.length == 0) 
            {
                loc3 = GameMapUtil.getTilePoint(loc1.x, loc1.y);
                if (!(loc3.x == this._lastPoint.x) || !(loc3.y == this._lastPoint.y)) 
                {
                    AIManager.onAIControl(this._lastPoint, AIType.AI_Drama);
                    return;
                }
                if (this._callback != null) 
                {
                    this._callback.apply();
                }
                return;
            }
            loc3 = GameMapUtil.getTilePoint(loc1.x, loc1.y);
            var loc2=this._points.shift();
            this._lastPoint = loc2;
            AIManager.onAIControl(loc2, AIType.AI_Drama);
            return;
        }

        public cancel(arg1: TDrama, arg2: Function=null): void
        {
            if (arg2 != null) 
            {
                arg2.apply();
            }
            return;
        }

        public dispose(): void
        {
            this._callback = null;
            return;
        }

        /* internal  */parseTargetPoints(arg1: TDrama): Array<any>
        {
            var loc4=null;
            var loc6=null;
            var loc7=null;
            var loc1=[];
            var loc2=arg1.route;
            if (loc2 == null || loc2 == "" || loc2.indexOf("[") < 0 || loc2.indexOf("]") < 0) 
            {
                return [];
            }
            var loc3=loc2.split("][");
            if (loc2.indexOf("][") < 0) 
            {
                loc3 = loc2.split("]");
                loc3 = String(loc3[0]).split("[");
                loc3 = String(loc3[1]).split(",");
                return [new Object /* flash.geom.Point */(int(loc3[0]), int(loc3[1]))];
            }
            var loc5=0;
            while (loc5 < loc3.length) 
            {
                loc6 = loc3[loc5];
                if (loc5 == 0) 
                {
                    loc6 = loc6.split("[")[1];
                }
                if (loc5 == (loc3.length - 1)) 
                {
                    loc6 = loc6.split("]")[0];
                }
                loc4 = loc6.split(",");
                (loc7 = new Object /* flash.geom.Point */()).x = int(loc4[0]);
                loc7.y = int(loc4[1]);
                loc1.push(loc7);
                ++loc5;
            }
            return loc1;
        }

        /* internal */ /* var */_points: Array<any>;

        /* internal */ /* var */_callback: Function;

        /* internal */ /* var */_lastPoint: Object /* flash.geom.Point */;
    }
